package com.numberone.web.controller.goodsImg;

import com.numberone.common.annotation.Log;
import com.numberone.common.base.AjaxResult;
import com.numberone.common.enums.BusinessType;
import com.numberone.common.page.TableDataInfo;
import com.numberone.common.utils.poi.ExcelUtil;
import com.numberone.framework.web.base.BaseController;
import com.numberone.system.domain.GoodsImg;
import com.numberone.system.service.IGoodsImgService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品图片 信息操作处理
 * 
 * @author numberone
 * @date 2020-09-28
 */
@Controller
@RequestMapping("/system/goodsImg")
public class GoodsImgController extends BaseController
{
    private String prefix = "system/goodsImg";
	
	@Autowired
	private IGoodsImgService goodsImgService;
	
	@RequiresPermissions("system:goodsImg:view")
	@GetMapping()
	public String goodsImg()
	{
	    return prefix + "/goodsImg";
	}
	
	/**
	 * 查询商品图片列表
	 */
	@RequiresPermissions("system:goodsImg:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(GoodsImg goodsImg)
	{
		startPage();
        List<GoodsImg> list = goodsImgService.selectGoodsImgList(goodsImg);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出商品图片列表
	 */
	@RequiresPermissions("system:goodsImg:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsImg goodsImg)
    {
    	List<GoodsImg> list = goodsImgService.selectGoodsImgList(goodsImg);
        ExcelUtil<GoodsImg> util = new ExcelUtil<GoodsImg>(GoodsImg.class);
        return util.exportExcel(list, "goodsImg");
    }
	
	/**
	 * 新增商品图片
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存商品图片
	 */
	@RequiresPermissions("system:goodsImg:add")
	@Log(title = "商品图片", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(GoodsImg goodsImg)
	{		
		return toAjax(goodsImgService.insertGoodsImg(goodsImg));
	}

	/**
	 * 修改商品图片
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		GoodsImg goodsImg = goodsImgService.selectGoodsImgById(id);
		mmap.put("goodsImg", goodsImg);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存商品图片
	 */
	@RequiresPermissions("system:goodsImg:edit")
	@Log(title = "商品图片", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(GoodsImg goodsImg)
	{		
		return toAjax(goodsImgService.updateGoodsImg(goodsImg));
	}
	
	/**
	 * 删除商品图片
	 */
	@RequiresPermissions("system:goodsImg:remove")
	@Log(title = "商品图片", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(goodsImgService.deleteGoodsImgByIds(ids));
	}
	
}
